﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Worldme.YHChatSDK.Common.Constant.Enums
{
    public enum ServerErrCode
    {
        SUCCESS,
        INVALID_PARAMETER,
        UNAUTHORIZED,
        BOT_BANNED,
        CHAT_BANNED,
        FREQUENCY_LIMIT
    }

    public static class ServerErrCodeExtensions
    {
        private static readonly Dictionary<ServerErrCode, (string Code, string Desc)> _serverErrCodeMap = new Dictionary<ServerErrCode, (string, string)>
    {
        { ServerErrCode.SUCCESS, ("1", "正常") },
        { ServerErrCode.INVALID_PARAMETER, ("1002", "参数缺失或者有误") },
        { ServerErrCode.UNAUTHORIZED, ("1003", "未授权") },
        { ServerErrCode.BOT_BANNED, ("1004", "机器人被封禁") },
        { ServerErrCode.CHAT_BANNED, ("1005", "会话被封禁") },
        { ServerErrCode.FREQUENCY_LIMIT, ("1007", "触发频次限制") },
    };

        public static string GetCode(this ServerErrCode serverErrCode)
        {
            if (_serverErrCodeMap.TryGetValue(serverErrCode, out var info))
                return info.Code;
            return string.Empty;
        }

        // 获取描述
        public static string GetDesc(this ServerErrCode serverErrCode)
        {
            if (_serverErrCodeMap.TryGetValue(serverErrCode, out var info))
                return info.Desc;
            return string.Empty;
        }

        // 根据 code 获取描述
        public static string GetDesc(string code)
        {
            foreach (var kvp in _serverErrCodeMap)
            {
                if (kvp.Value.Code == code)
                    return kvp.Value.Desc;
            }
            return string.Empty;
        }

        // 检查是否存在某个 code
        public static bool HasCode(string code)
        {
            foreach (var kvp in _serverErrCodeMap)
            {
                if (kvp.Value.Code == code)
                    return true;
            }
            return false;
        }



    }
}
